import LogicFlow, { BaseNodeModel, GraphConfigData } from '@logicflow/core';
import MyParse from "./src/parse/MyParse";
import { registerAll, AllNode } from './src/nodes/index';
import { Group } from '@logicflow/extension';


class LiteFlow extends Group {
    static pluginName = 'lite';

    constructor({ lf }: { lf: LogicFlow }) {
        super({ lf })
        //注册所有节点
        registerAll(lf)

        lf.setMenuConfig({
            nodeMenu: [
                {
                    text: '删除',
                    callback(node) {
                        lf.deleteNode(node.id);
                    },
                }, {
                    text: '仅删除分组节点',
                    callback(node) {
                        const group = lf.getNodeModelById(node.id);
                        group.children.forEach(cId => {
                            group.removeChild(cId)
                        })
                        lf.deleteNode(node.id);
                    }
                }
            ], // 覆盖默认的节点右键菜单
            edgeMenu: [
                {
                    text: '删除',
                    callback(edge) {
                        lf.deleteEdge(edge.id);
                    },
                }
            ], // 删除默认的边右键菜单
            graphMenu: [],  // 覆盖默认的边右键菜单，与false表现一样
        });
    }
}

const parse = (data: GraphConfigData) => {
    return new MyParse(data).parse().getElString();
    // return new MyParse(data).parse().toLogicNode().getElString();
}

export {
    LiteFlow,
    AllNode,
    parse
};
